﻿@{
    Layout = null;
}
<script src="~/Assets/js/jquery.form.js"></script>
<script src="~/assets/js/jquery.validate.min.js"></script>
<div class="row">
    <form class="form-horizontal" role="form" id="frmUserRelationAdd">
        <input type="text" style="visibility:hidden" value="@Request.Params["orgId"]" id="orgId" name="orgId" />
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="name"> 姓名 </label>

            <div class="col-sm-9">
                <input type="text" id="name" name="name" placeholder="姓名" class="col-xs-12 col-sm-9">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label no-padding-right" for="account"> 用户名 </label>
            <div class="col-sm-9">
                <input type="text" id="account" name="account" placeholder="用户名" class="col-xs-12 col-sm-9">
            </div>
        </div>
        <div class="col-md-offset-3 col-md-9">
            <button class="btn btn-info" type="submit">
                <i class="icon-ok bigger-110"></i>
                提交
            </button>

            &nbsp; &nbsp; &nbsp;
            <button class="btn" type="reset">
                <i class="icon-undo bigger-110"></i>
                重设
            </button>
        </div>
    </form>
</div>
<script>
    function doAddUserRelation() {
        $("#frmUserRelationAdd").ajaxSubmit({
            type: "POST",
            url: "/organizeapi/CreateAndAddMember",
            success: function (response, statusText) {
                if (response.ResultCode != 4040)
                {
                    var ref = $('#orgTree').jstree(true);
                    ref.refresh();
                    bootbox.dialog({
                        message: response.Message,
                        buttons: {
                            "success": {
                                "label": "确定",
                                "className": "btn-sm btn-primary"
                            }
                        }
                    });
                }
                else
                {
                    bootbox.confirm("指定账户名已存在，继续将会使用账户名对应的用户作为成员添加至组织机构中，要继续么？", function (res) {
                        if (res == true) {
                            $("#frmUserRelationAdd").ajaxSubmit({
                                type: "POST",
                                url: "/organizeapi/AddMember",
                                success: function (response, statusText) {
                                    bootbox.dialog({
                                        message: response.Message,
                                        buttons: {
                                            "success": {
                                                "label": "确定",
                                                "className": "btn-sm btn-primary"
                                            }
                                        }
                                    });
                                    var ref = $('#orgTree').jstree(true);
                                    ref.refresh();
                                }
                            });
                        } else {
                            var ref = $('#orgTree').jstree(true);
                            ref.refresh();
                        }
                    });
                }
            }
        })
    };
    $('#frmUserRelationAdd').validate(buildOpt(doAddUserRelation, function () { }));
</script>